<?php 
	require_once("init.php"); 
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>iVote</title>
<meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
<style type="text/css" media="screen">@import "iui/iui.css";</style>
<style type="text/css" media="screen">@import "lib/main.css";</style> 
<script type="application/x-javascript" src="iui/iui.js"></script>
<script type="text/javascript" src="lib/ajax.js"></script>
<script type="text/javascript" src="lib/script.js"></script>
</head>
 
<body>
	<div class="toolbar">
    <h1 id="pageTitle"></h1>
    <a id="backButton" class="button" href="#"></a>
    <a id="toolbarButton" class="button" href=""></a>
  </div>
  
  <?php
		require("login.php");
		require("submittopic.php");
	?>
      
  <form id="searchForm" class="panel" title="Search" method="post" action="searchtopics.php">
    <fieldset>
      <label>Keyword:</label>
      <input type="text" name="keyword" />
      <label>Include:</label>
      <select name="status">
      	<option value="all">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;All topics</option>
      	<option value="open">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Open topics</option>
      	<option value="closed">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Closed topics</option>
      </select>
    </fieldset>
    <div class="center">
    	<a class="button" type="submit">Start Search</a>
    </div>
  </form>
      
  <form id="registerForm" class="panel" title="Sign Up" method="post" action="register.php">
    <fieldset>
      <label>Username:</label>
      <input type="text" name="username" maxlength="20" />
      <label>Password:</label>
      <input type="password" name="password" maxlength="20" />
      <label>Re-type Password:</label>
      <input type="password" name="password2" maxlength="20" />
      <label>Email:</label>
      <input type="text" name="email" maxlength="100" />
    </fieldset>
    <div class="center">
      <p>Pushing 'I accept' means that you agree to the <a href="legal.html">iVote Disclaimer</a> and <a href="legal.html">Privacy Policy</a>.</p>
    	<a class="button" type="submit">I accept</a>
    </div>
  </form>
  
  <form id="forgotPasswordForm" class="panel" title="Forgot Password" method="post" action="forgot.php">
    <fieldset>
      <label>Username:</label>
      <input type="text" name="username" />
      <label>Email:</label>
      <input type="text" name="email" />
    </fieldset>
    <div class="center">
      <p>Your password will be sent to your email address shortly.</p>
    	<a class="button" type="submit">Retrieve password</a>
    </div>
  </form>
  
  <!-- HOME -->  
	<ul id="home" title="iVote" selected="true" showToolbarButton="true" 
  	<?php
    	if (!isset($_SESSION["username"])) {
		?>
  	toolbarButtonText="Sign in" 
    toolbarButtonHREF="#loginForm"
    <?php
			} else {
		?>
    toolbarButtonText="Sign out" 
    toolbarButtonHREF="logout.php"
    <?php
			}
		?>
  >
    <li><a href="#searchForm">Search</a></li>
    <li><a href="topics.php">Open Topics</a></li>
		<?php
    	if (isset($_SESSION["username"])) {
		?>
    <li><a href="mytopics.php">My Topics</a></li>
    <li><a href="moderation.php">Moderation</a></li>
    <li><a href="profile.php">My Profile</a></li>
    <?php
			} else {
		?>
    <li class="disabled">My Topics</li>
    <li class="disabled">Moderation</li>
    <li class="disabled">My Profile</li>
    <li><a href="#registerForm">Sign Up</a></li>
    <?php
			}
    ?>
    <li><a href="#settings">Settings</a></li>
    <li><a href="about.html">About</a></li>
  </ul>
  
	<form id="settings" name="frmSettings" class="panel" title="Settings" method="post" 
  		action="javascript:post($('settings'), 'savecategory.php')">
    <h2>Categories</h2>
    <fieldset class="div-panel-style">
    	<input type="hidden" id="category-0" name="categories[]" value="0" />
			<?php
				$qCategories = mysql_query("
					SELECT *
					FROM categories
					ORDER BY categoryId
				");
				$arCategories = listToArray($_SESSION["categories"], ",");
				while ($row =  mysql_fetch_array($qCategories)) {
					$categoryId = $row["categoryId"];
			?>
	  	<input type="hidden" 
      		id="category-<?php print $categoryId; ?>" 
      		name="categories[]" 
 		     	value="<?php if (in_array($categoryId, $arCategories)) print $categoryId; else print ''; ?>" />
      <div class="row">
        <label><?php print $row["name"]; ?></label>
        <div class="toggle" onclick="toggleValue($('category-<?php print $categoryId; ?>'), '<?php print $categoryId; ?>', ''); document.frmSettings.submit();" toggled="<?php if (in_array($categoryId, $arCategories)) print "true"; else print "false"; ?>"><span class="thumb"></span><span class="toggleOn">ON</span><span class="toggleOff">OFF</span></div>
      </div>
      <?php
				}
			?>
    </fieldset>
  </form>
</body>

<?php
	require_once("end.php");
?>
</html>